package com.fhc.view



import androidx.compose.animation.core.*
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.unit.Dp
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp



@Composable
fun FhcAnimatedCombinedIcon(
    mainIcon: ImageVector,
    secondaryIcon: ImageVector,
    mainTint: Color = LocalContentColor.current,
    secondaryTint: Color = LocalContentColor.current,
    sizeRatio: Float = 0.5f,
    containerSize: Dp = 26.dp,
    modifier: Modifier = Modifier
) {
    require(sizeRatio in 0.1f..0.9f) { "sizeRatio must be between 0.1 and 0.9" }

    var isActive by remember { mutableStateOf(true) }
    val infiniteTransition = rememberInfiniteTransition()
    val rotation by infiniteTransition.animateFloat(
        initialValue = 0f,
        targetValue = if (isActive) 360f else 0f,
        animationSpec = infiniteRepeatable(
            animation = tween(2000, easing = LinearEasing)
        )
    )

    DisposableEffect(Unit) {
        onDispose {
            isActive = false
        }
    }

    Box(modifier = modifier) {
        Icon(
            imageVector = mainIcon,
            contentDescription = "Main Icon",
            tint = mainTint,
            modifier = Modifier.size(containerSize)
        )

        Icon(
            imageVector = secondaryIcon,
            contentDescription = "Rotating Icon",
            tint = secondaryTint,
            modifier = Modifier
                .size(containerSize * sizeRatio)
                .align(Alignment.Center)
                .rotate(rotation)
        )
    }
}


